package com.zy.configs;

import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;

/**
 * @program: shopping153_cloud
 * @description: 指定feign文件上传的协议
 * @author: zy
 * @create: 2025-08-22 17:02
 */
public class FeignMultipartSupportConfig {
    // Required for Feign to work with HttpMessageConverters (like for JSON)
    private final ObjectFactory<HttpMessageConverters> messageConverters;

    public FeignMultipartSupportConfig(ObjectFactory<HttpMessageConverters> messageConverters) {
        this.messageConverters = messageConverters;
    }
    @Bean
    public Encoder feignFormEncoder() {
        // This combines Spring's encoders with the FormEncoder to handle multipart requests
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
    }

}
